﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Thauan_Juliano_World
{
    public class GameObject
    {
        public List<GameObject> list = new List<GameObject>();
        public VertexPositionColor[] verts;
        public VertexPositionTexture[] vertsTexture;
        public PrimitiveType pt = PrimitiveType.TriangleStrip; // USAR !!
        public int offset = 0;
        public int count = 2;
        public Texture2D texture;
        public bool VertexTexture = false;
        public float alpha = 1;

        public Vector3 position = new Vector3(0,0,0);

        public Matrix world;

        public GameObject(VertexPositionColor[] verts, int offset, int count, List<GameObject> list, Matrix world, Vector3 position)
        {
            this.verts = verts;
            this.offset = offset;
            this.count = count;
            this.list = list;
            this.position = position;
            this.world = world;

            list.Add(this);

        }

        public GameObject(VertexPositionTexture[] verts, int offset, int count, List<GameObject> list, Matrix world, Vector3 position, Texture2D texture)
        {
            this.texture = texture;
            this.vertsTexture = verts;
            this.offset = offset;
            this.count = count;
            this.list = list;
            this.position = position;
            this.world = world;

            this.VertexTexture = true;

            list.Add(this);

        }

        public void Destroy() 
        {
            this.list.Remove(this);
        }

        public void ResetPosition() 
        {
            this.world.M41 = 0;
            this.world.M42 = 0;
            this.world.M43 = 0;
        }

        public void SetPosition() 
        {
            this.world.M41 = position.X;
            this.world.M42 = position.Y;
            this.world.M43 = position.Z;
        }

        public void SetForWath() 
        {
            if (VertexTexture)
            {
                Inventory.getBasicEffect().VertexColorEnabled = false;
                Inventory.getBasicEffect().TextureEnabled = true;
            }
            else 
            {
                Inventory.getBasicEffect().VertexColorEnabled = true;
                Inventory.getBasicEffect().TextureEnabled = false;   
            }
        }

        public bool isForTexture()
        {
            if (VertexTexture)
            {
                return true;
            }

            return false;
        }
    }
}
